"""
@filename: school.py
@project: flask_project
@author: wlf
@time: 2022-09-04
学校表
"""
from model import db
import datetime


class School(db.Model):
    __tablename__ = "school"  # 映射的数据库，不写默认是类名
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    school_name = db.Column(db.String(128), nullable=False)
    head_portrait = db.Column(db.String(128), nullable=True)  # 存放图片路径
    introduction = db.Column(db.String(512), nullable=False)
    delete = db.Column(db.Integer, default=0, nullable=False)

    CreatedAt = db.Column(db.DateTime, default=datetime.datetime.now())
    UpdatedAt = db.Column(db.DateTime, default=None, onupdate=datetime.datetime.now())

    admin = db.relationship("Admin", backref="school")  # 一对多关系

    def to_json1(self):
        return {
            "school_name": self.school_name,
            "introduction": self.introduction,
            "Create time": self.CreatedAt.strftime('%Y-%m-%d %H:%M:%S'),
        }
